import Opt from '@/components/dt/info/Opt.js'
import ruleOpt from '@/biz/option/rule.js'

class NewOpt extends Opt {
  constructor(info, isLockTime) {
    super(info)
    this.isLockTime = isLockTime
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.part1)
  }

  createAll() {
    this.month = {
      title: '奖金单月份',
      key: 'bonusMonth',
      disabled: this.isLockTime != null ? this.isLockTime : true,
      date: {
        type: 'month'
      },
      rules: [ruleOpt.required('请选择奖金单月份')]
    }
    this.part1 = [
      {
        title: '奖金单名称',
        placeholder: '请输入奖金名称',
        key: 'bonusName',
        col: 20,
        input: {},
        rules: [ruleOpt.required('请输入奖金名称')]
      },
      {
        title: '奖金单类型',
        key: 'bonusType',
        col: 20,
        select: {
          key: 'bonusType'
        },
        rules: [ruleOpt.required('请选择奖金单类型')],
        change: () => {
          if (this.info.bonusType == 'SPECIAL') {
            if (this.opts.indexOf(this.special) < 0) {
              this.opts.push(this.special)
              this.opts.push(this.reason)
            }
          } else {
            this.opts.remove(this.special)
            this.opts.remove(this.reason)
          }
        }
      },
      this.month
    ]
    this.special = {
      title: '特殊奖金单类型',
      col: 20,
      key: 'scaleType',
      placeholder: '请选择特殊奖金单原因',
      select: {
        key: 'specialType'
      },
      rules: [ruleOpt.required('请选择特殊奖金单原因')]
    }
    this.reason = {
      title: '原因',
      col: 20,
      key: 'reason',
      input: {
        type: 'textarea',
        autosize: {
          minRows: 2
        }
      },
      rules: [ruleOpt.required('请输入原因'), ruleOpt.max(300)]
    }
  }
}

export default NewOpt
